package xyz.heyaoshare.config.mybatis;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.mybatis.FlexConfiguration;
import com.mybatisflex.spring.boot.ConfigurationCustomizer;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import xyz.heyaoshare.config.mybatis.entity.BaseEntity;
import xyz.heyaoshare.config.mybatis.entity.SimpleEntity;
import xyz.heyaoshare.config.mybatis.listener.InsertListenerHandler;
import xyz.heyaoshare.config.mybatis.listener.UpdateListenerHandler;

/**
 * MybatisFlex配置类
 * @author YueHe
 * @version 0.0.1
 * @since 2025/6/25 上午11:01
 * <br/>
 * 初始化配置：{@link MyBatisFlexCustomizer}
 * <br>
 * 自定义的配置：{@link ConfigurationCustomizer}
 */
@Configuration
@EnableTransactionManagement
@MapperScan("xyz.heyaoshare.core.mapper")
public class MybatisFlexConfig implements ConfigurationCustomizer, MyBatisFlexCustomizer {

    @Override
    public void customize(FlexConfiguration configuration) {
    }

    @Override
    public void customize(FlexGlobalConfig globalConfig) {
        globalConfig.registerUpdateListener(new UpdateListenerHandler(), BaseEntity.class, SimpleEntity.class);
        globalConfig.registerInsertListener(new InsertListenerHandler(), BaseEntity.class);
    }

}